package com.lmind.core.gps.publish;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Map;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.lmind.core.publish.Publisher;
import com.lmind.core.publish.Subscriber;

public class DefaultRmiGroupPublisher implements RmiGroupPublisher {
	
	private Publisher groupPublisher;

	public Publisher getGroupPublisher() {
		return groupPublisher;
	}

	public void setGroupPublisher(Publisher groupPublisher) {
		this.groupPublisher = groupPublisher;
	}

	/* (non-Javadoc)
	 * @see com.lmind.core.gps.publish.RmiGroupPublisher#subscribeGroup(java.lang.String, java.lang.String)
	 */
	@Override
	public void subscribeGroup(String group, String rmiUrl) throws MalformedURLException, RemoteException, NotBoundException {
		Object o = Naming.lookup(rmiUrl);
		Class<?>[] clazz = o.getClass().getInterfaces();
		Subscriber subscriber =  (Subscriber)o;
		groupPublisher.subscribe(subscriber, group);
	}
}
